import com.alibaba.fastjson.JSONObject;

import java.util.*;

public class PointDataContainer {


    private PointDataContainer() {
    }

    /**
     * 获取单例实例
     *
     * @return the instance
     */
    public static final PointDataContainer getInstance() {
        return PointDataContainer.LazyHolder.INSTANCE;
    }


    private static class LazyHolder {
        private static final PointDataContainer INSTANCE = new PointDataContainer();
    }


    private Map<Integer, BasePointData> pointDataMap = new HashMap<>();


    public void add2PointDataMap(BasePointData pointData){
        ProtocolDataContainer.getInstance().removeCalculatorTask(pointData.getPoint());
        this.pointDataMap.put(pointData.getPoint(),pointData);
        pointData.joinRealTimeData();
    }

    public void deleteFromPointDataMap(Integer point){
        this.pointDataMap.remove(point);
        ProtocolDataContainer.getInstance().removeCalculatorTask(point);
    }

    public JSONObject getAllPoint(){
        JSONObject jsonObject=new JSONObject();
        for(Integer i: new TreeSet<>(this.pointDataMap.keySet())){
            jsonObject.put(i+"",this.pointDataMap.get(i).getValue());
        }
        return jsonObject;
    }

}
